﻿using DataServer.ApplicationLib.Entities;

namespace DataServer.ApplicationLib.Rules
{
    public static class RuleHelper
    {
        internal static int GetInvalidRowCount(IList<ConfigDataCheckEntity> data)
        {
            return GetInvalidRowList(data).Count;
        }

        internal static IList<ConfigDataCheckEntity> GetInvalidRowList(IList<ConfigDataCheckEntity> data)
        {
            IList<ConfigDataCheckEntity>? invalidRowList = null;
            if (null != data && data.Count > 0)
            {
                invalidRowList = data.Where(i => !string.IsNullOrEmpty(i.IsValid) && i.IsValid.Equals(VerifyResultColumns.InvalidVal))
                                     .ToList();
            }
            if (null == invalidRowList)
            {
                invalidRowList = new List<ConfigDataCheckEntity>();
            }

            return invalidRowList;
        }

        internal static IControlModelVerify? ParaseControlVerify(this ConfigFieldEntity field, string? checkWay)
        {
            IControlModelVerify? retObj = null;
            if (!string.IsNullOrWhiteSpace(field.ControlContent))
            {
                retObj = ControlVerifyFactory.CreateVerify(new CreateCtrlVerifyInput
                {
                    CheckWay = checkWay,
                    ControlType = field.ControlType,
                    ControlContent = field.ControlContent,
                    TargetFieldColumn = field.ValueColumnMap
                });
            }
            return retObj;
        }
    }
}
